<%@ page import="cn.com.betasoft.dsat.web.ap.helpers.ResourceUriHelper; cn.com.betasoft.dsat.web.ap.helpers.ManagedCategoryHelper" %>

<div style="width:60%;min-width:900px;margin-left:10px;">
    <div style="float:left">
        <ul class="ui-controlbar">
            <%~ render("shared/list_item.html.gst", [type:"controlbar",id:"addResource",url:"#",label:l("mos.text.addInstance")]) %>
        </ul>
        <ul id="addResourceMenu" class="ui-menu ui-hide">
            <% ManagedCategoryHelper.eachClass {id,label,type->
                def url = ResourceUriHelper.buildManagedCategoryAddUri(type);
                out.print render("shared/list_item.html.gst", [type:"menu",id:id,url:url,label:label]);
            }; %>
        </ul>
    </div>
    <div style="float:left;margin-top:10px;margin-left: 200px;">
        <input id="search" type="text" class="ui-textbox ui-searchbox" />
        <%~ render("shared/button.html.gst", [id:"btnSearch",action:"#",label:l("common.text.search")]) %>
    </div>
</div>
<script language="javascript">
    $(function() {
        $("#addResource").after($("#addResourceMenu"));
        $("#addResourceMenu").menu();
        $("#addResource").menubutton();

        $("#btnSearch").bind("click", function(){
            var searchText = document.getElementById('search').value;
            if (!searchText||searchText.isEmpty()) {
                $.ui.messageBox.show({title:'<%~ l("common.text.search") %>',msg:'<%~ l("common.text.confirmSearch")%>',buttons:$.ui.messageBox.OK});
                return;
            }
            window.location='/mos/search/index?q=' + encodeURI(searchText);
        });

        $("#batchExport").bind("click", function(){
            var win = $("body").dialog({
                           "title":"<%~ l('mos.text.selectResource')%>","closable":true,"modal":true,
                           "html":"<div id='treeContainer'></div>",
                           "width":"300px",
                           "height":"350px",
                           "buttons":[
                                    {text:"<%~ l("common.text.ok")%>",handler:function(){
                                        alert($("#treeContainer").data("moTree").getSelections().length);return true;
                                    }},
                                    {text:"<%~ l("common.text.cancel")%>",handler:'return true;'}
                           ]
                       }).data("dialog");
            win.accept($("#treeContainer").moTree({"delayLoad":true,"enableCheck":true}).data("moTree"));
            win.show();
        });
    })
</script>




